<?php
if (!function_exists('lock_stock_regular')) {
    function lock_stock_regular($warrantyType,$brandId,$elementSaleId,$point){
        $stockList=array();   
        $CI =& get_instance();
        $table='wms_warehouse_list';
        if(is_numeric($elementSaleId) and $elementSaleId<>0){
                $whereArray = array('point' => $point,
                                    'platform_num' => $elementSaleId,
                                    'active'=>1);
                $result=$CI->common_model->selectFirst($table,$whereArray);
                if(count($result)>0){
                    $elementStock=array('whs_code'=>$result['whs_code'],'whs_type'=>$result['whs_type']);
                }
        }
        if(is_numeric($brandId) and $brandId<>0){
                $whereArray = array('point' => $point,
                                    'platform_num' => $brandId,
                                    'active'=>1);
                $result=$CI->common_model->selectFirst($table,$whereArray);
                if(count($result)>0){
                    $brandStock=array('whs_code'=>$result['whs_code'],'whs_type'=>$result['whs_type']);
                }
        }
        $whereArray = array('point' => $point,
                            'whs_type' =>'maintain',
                            'active'=>1);
        $result=$CI->common_model->selectFirst($table,$whereArray);
        if(count($result)>0){
               $maintainStock=array('whs_code'=>$result['whs_code'],'whs_type'=>$result['whs_type']);
        }
        if($warrantyType==0){  //保外 先电商 后品牌
             if($elementStock<>null){
                 $stockList[]=$elementStock;
             }
             if($brandStock<>null){
                 $stockList[]=$brandStock;
             }
        }elseif($warrantyType==1){ //保内  后品牌 先电商
             if($brandStock<>null){
                 $stockList[]=$brandStock;
             }
             if($elementStock<>null){
                 $stockList[]=$elementStock;
             }
        }
        if($maintainStock<>null){ //保内保外维保仓都在最后
            $stockList[]=$maintainStock;
        }
        return $stockList;
    }
}

